package utilities;

import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;

import co.id.btel.create.pdf.PdfCustomer;

import com.itextpdf.text.BadElementException;
import com.itextpdf.text.Document;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.PdfWriter;

public class BackgroundImg {
	private static String FILE = "E:/BTE/samplePdf/Image.pdf";
	private static String IMG = "F:/app_3/workspace/BTEService/data/Polos1.jpg";

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			Document document = new Document();
			PdfWriter.getInstance(document, new FileOutputStream(FILE));
			document.open();
			document.add(addImgBackground(IMG));
			PdfCustomer.addCustomer(document);
			PdfUtil.addMetaData(document);
			document.close();
			System.out.print("done!");
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static Image addImgBackground(String path)
			throws BadElementException, MalformedURLException, IOException {
		Image img = Image.getInstance(path);
		img.scaleToFit(PageSize.LEGAL.getHeight() * 1.38f,
				PageSize.LEGAL.getWidth() * 1.38f);
		img.setAbsolutePosition(0, 0);
		return img;
	}

}
